package com.timebank.score.controller;

import com.timebank.common.core.web.controller.BaseController;
import com.timebank.common.core.web.page.TableDataInfo;
import com.timebank.common.core.web.pojo.AjaxResult;
import com.timebank.common.security.annotation.RequiresLogin;
import com.timebank.score.pojo.entity.ScoreTask;
import com.timebank.score.pojo.vo.ScoreTaskVO;
import com.timebank.score.service.ScoreTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 积分任务 控制层
 * @author shiliuyinzhen
 */
@RestController
@RequestMapping("/task")
@Api(tags = "积分任务相关接口")
public class ScoreTaskController extends BaseController {

    @Resource
    private ScoreTaskService scoreTaskService;

    /**
     * 新增积分任务
     * @param scoreTask
     * @return
     */
    @RequiresLogin
    @PostMapping
    @ApiOperation("新增积分任务")
    public AjaxResult addScoreTask(@RequestBody ScoreTask scoreTask){
        return scoreTaskService.addScoreTask(scoreTask);
    }

    /**
     * 修改积分任务
     * @param scoreTask
     * @return
     */
    @RequiresLogin
    @PutMapping("/{taskId}")
    @ApiOperation("修改积分任务")
    public AjaxResult updateScoreTask(@PathVariable("taskId") Long taskId,@RequestBody ScoreTask scoreTask){
        scoreTask.setId(taskId);
        return scoreTaskService.updateScoreTask(scoreTask);
    }

    /**
     * 查询积分任务列表
     * @param scoreTask
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("查询积分任务列表")
    public TableDataInfo getScoreTaskList(ScoreTask scoreTask){
        startPage();
        List<ScoreTaskVO> list = scoreTaskService.getScoreTaskList(scoreTask);
        return getDataTable(list);
    }

    /**
     * 批量删除积分任务
     * @param taskIds
     * @return
     */
    @RequiresLogin
    @DeleteMapping("/{taskIds}")
    @ApiOperation("批量删除积分任务")
    public AjaxResult batchDeleteScoreTask(@PathVariable("taskIds") Long[] taskIds){
        return scoreTaskService.batchDeleteScoreTask(taskIds);
    }

    /**
     * 批量领取积分任务奖励
     * @param taskIds
     * @return
     */
    @RequiresLogin
    @PostMapping("/getRewards/{taskIds}")
    @ApiOperation("批量领取积分任务奖励")
    public AjaxResult batchGetRewards (@PathVariable("taskIds") Long[] taskIds){
        return scoreTaskService.batchGetRewards(taskIds);
    }
}
